package com.hjj.concurrence.volatileTest;

/**
 * @author hjj
 * @create 2019-12-16 11:18
 */
public class VolatileBarrierExample {
    int a = 0;
    volatile int v1 = 1;
    volatile int v2 = 2;

    void readAndWrite() {
        int i = v1; // volatile读
        int j = v2; // volatile读
        a = i + j; // 普通读
        v1 = i + 1; // volatile写
        v2 = j * 2; // volatile写
    }
}
